package com.jzt.qf.service.impl;
/**
 　* @description:销售退回单service实现类
 　* @author zxy
 　* @date 2020-07-23 14:59
 　*/

import com.alibaba.fastjson.JSON;
import com.jzt.qf.beans.HttpResult;
import com.jzt.qf.beans.UploadBase;
import com.jzt.qf.beans.jztBean.InStockPlan_Upload;
import com.jzt.qf.beans.qfBean.ZxyUploadbillJzt;
import com.jzt.qf.dao.SaleBackBillDao;
import com.jzt.qf.dao.UploadbillJztDao;
import com.jzt.qf.https.JztApi;
import com.jzt.qf.service.SaleBackBillService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
@Slf4j
public class SaleBackBillServiceImpl  implements SaleBackBillService {
    @Autowired
    private SaleBackBillDao saleBackBillDao;
    @Resource
    private UploadbillJztDao uploadbillJztDao;
    @Resource
    private JztApi jztApi;
    @Override
    public HttpResult uploadSaleBackBill(String billCode) {

        log.info("上传销售退回单SaleBackBillServiceImpl访问成功");
        //获取采购订单
        List<InStockPlan_Upload> inStockPlan_uploads =
                saleBackBillDao.getSaleBackBill_Upload(billCode);
        log.info("销售退回单" + JSON.toJSONString(inStockPlan_uploads));
        HttpResult httpResult = jztApi.HttpRequest(
                new UploadBase("xt", "saveData", inStockPlan_uploads));
        log.info("上传销售退回单返回数据" + JSON.toJSONString(httpResult));
        if (httpResult.isFlag()) {
            for (InStockPlan_Upload inStockPlan_upload : inStockPlan_uploads) {
                ZxyUploadbillJzt zxyUploadbillJzt = new ZxyUploadbillJzt();
                zxyUploadbillJzt.setBillcode(inStockPlan_upload.getBUSINESSBILL_NO());
                zxyUploadbillJzt.setOrd(Integer.parseInt(inStockPlan_upload.getBILL_DTL_ID_OLD()));
                zxyUploadbillJzt.setBilltype(45);
                uploadbillJztDao.updateFlags(zxyUploadbillJzt);
            }
        }
        return httpResult;
    }
}
